<template>
  <!-- 会员列表 -->
  <div class="info">
    <template>
      <el-skeleton :loading="loading" />
    </template>
    <template v-if="!loading">
      <el-form :model="searchInfo" inline>
        <el-form-item>
          <el-input clearable v-model="searchInfo.nickname" placeholder="请输入会员昵称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input clearable v-model="searchInfo.phone" placeholder="请输入手机号码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="searchInfo.sex" placeholder="请选择会员性别">
            <el-option value="0" label="女"></el-option>
            <el-option value="1" label="男"></el-option>
            <el-option value="2" label="未知"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="searchInfo.status" placeholder="请选择会员状态">
            <el-option value="0" label="禁用"></el-option>
            <el-option value="1" label="可用"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
          <el-button icon="el-icon-refresh-right" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="vipList" border>
        <el-table-column label="会员编号" prop="vipId"/>
        <el-table-column label="会员昵称" prop="nickname"/>
        <el-table-column label="会员性别" prop="sex">
          <template slot-scope="scope">
            <el-col v-if="scope.row.sex===0">女</el-col>
            <el-col v-if="scope.row.sex===1">男</el-col>
            <el-col v-if="scope.row.sex===2">未知</el-col>
          </template>
        </el-table-column>
        <el-table-column label="会员生日" prop="birthday"/>
        <el-table-column prop="avatar" header-align="center" align="center" label="头像">
          <template slot-scope="scope">
            <el-image   style="width: 80px" fit="cover" title="点击查看详情" :src="baseImagePath+scope.row.avatar"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="城市" prop="city"/>
        <el-table-column label="手机" prop="phone"/>
        <el-table-column label="职业" prop="job"/>
        <el-table-column label="会员详情" width="105px">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="showInfo(scope.row.vipId)">会员详情</el-button>
          </template>
        </el-table-column>
        <el-table-column label="电影收藏" width="105px">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="showFilm(scope.row.vipId)">查看电影</el-button>
          </template>
        </el-table-column>
        <el-table-column label="演员收藏" width="105px">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="showPerformer(scope.row.vipId)">查看演员</el-button>
          </template>
        </el-table-column>
        <el-table-column label="会员评论" width="105px">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="showComment(scope.row.vipId)">查看评论</el-button>
          </template>
        </el-table-column>
        <el-table-column label="信息状态" prop="status">
          <template slot-scope="scope">
            <el-button size="small" type="success" v-if="scope.row.status===1" @click="changStatus(scope.row)">启用</el-button>
            <el-button size="small" v-else type="danger" @click="changStatus(scope.row)" >禁用</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="105px">
          <template slot-scope="scope">
            <el-button type="danger" size="small" @click="delInfo(scope.row.vipId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="total,prev,pager,next,sizes,jumper"
                     :total="pageInfo.totalCount"
                     :page-size="pageInfo.size"
                     :current-page="pageInfo.current"
                     :page-sizes="[5,10,20,30,50,100]"
                     @size-change="sizeChange"
                     @current-change="currentChange"
      />
    </template>
    <el-dialog title="会员详情" :visible.sync="vipInfoVisible">
      <VipInfo ref="vipInfo"/>
    </el-dialog>
    <el-dialog title="收藏电影列表" :visible.sync="filmVisible">
      <Film ref="film"/>
    </el-dialog>
    <el-dialog title="关注演员列表" :visible.sync="performerVisible">
      <Performer ref="performer"/>
    </el-dialog>
    <el-dialog title="会员评论列表" :visible.sync="commentVisible">
      <Comment ref="comment"/>
    </el-dialog>
  </div>
</template>

<script>
import VipInfo from './collect/VipInfo'
import Film from './collect/Film'
import Performer from './collect/Performer'
import Comment from './collect/Comment'
export default {
  name: 'Vip',
  components: {
    VipInfo,
    Film,
    Performer,
    Comment
  },
  data () {
    return {
      loading: false,
      searchInfo: {
        nickname: '',
        phone: '',
        status: '',
        sex: '',
        page: 1,
        limit: 10
      },
      vipList: [],
      pageInfo: {
        totalCount: 0,
        currPage: 0,
        pageSize: 0,
        totalPage: 0
      },
      vipInfoVisible: false,
      filmVisible: false,
      performerVisible: false,
      commentVisible: false,
      baseImagePath: process.env.VUE_APP_BASE_API + '/img/'
    }
  },
  methods: {
    getList () {
      this.$http.get('/sys/vip/list', this.searchInfo).then(({ data }) => {
        this.loading = false
        if (data.code === 200) {
          this.vipList = data.data.list
          this.pageInfo.totalCount = data.data.totalCount
          this.pageInfo.currPage = data.data.currPage
          this.pageInfo.pageSize = data.data.pageSize
          this.pageInfo.totalPage = data.data.totalPage
        }
      })
    },
    sizeChange (limit) {
      this.searchInfo.limit = limit
      this.getList()
    },
    currentChange (page) {
      this.searchInfo.page = page
      this.getList()
    },
    delInfo (id) {
      this.$confirm('确定删除该数据吗？', '询问').then(() => {
        this.$axios.delete(`sys/vip/delete/${id}`).then(({ data }) => {
          if (data.code === 200) {
            this.$message({
              message: '删除成功',
              type: 'success',
              onClose: () => {
                this.getList()
              }
            })
          } else {
            this.$alert('删除失败！', { type: 'error' })
          }
        })
      })
    },
    resetForm () {
      this.searchInfo.nickname = ''
      this.searchInfo.phone = ''
      this.searchInfo.sex = ''
      this.searchInfo.status = ''
      this.getList()
    },
    changStatus (vip) {
      this.$confirm(`确定${vip.status === 1 ? '禁用' : '启用'}该会员吗？`).then(() => {
        this.$http.post('/sys/vip/status', { vipId: vip.vipId, status: vip.status === 1 ? 0 : 1 }).then(({ data }) => {
          if (data.code === 200) {
            this.$message.success('更改状态成功')
            this.getList()
          }
        })
      })
    },
    showInfo (vipId) {
      this.vipInfoVisible = true
      this.$nextTick(() => {
        this.$refs.vipInfo.init(vipId)
      })
    },
    showFilm (vipId) {
      this.filmVisible = true
      this.$nextTick(() => {
        this.$refs.film.init(vipId)
      })
    },
    showPerformer (vipId) {
      this.performerVisible = true
      this.$nextTick(() => {
        this.$refs.performer.init(vipId)
      })
    },
    showComment (vipId) {
      this.commentVisible = true
      this.$nextTick(() => {
        this.$refs.comment.init(vipId)
      })
    }
  },
  created () {
    this.$nextTick(() => {
      this.getList()
    })
  }
}
</script>

<style scoped>

</style>
